
#include "bsp.h"
#include "bsp_temperature.h"


#define TAG "TEMPERATURE"


void tempsensor_example(void *arg)
{
    // Initialize touch pad peripheral, it will start a timer to run a filter
    ESP_LOGI(TAG, "Initializing Temperature sensor");
    float tsens_out;
    temp_sensor_config_t temp_sensor = TSENS_CONFIG_DEFAULT();
    temp_sensor_get_config(&temp_sensor);
    ESP_LOGI(TAG, "default dac %d, clk_div %d", temp_sensor.dac_offset, temp_sensor.clk_div);
    temp_sensor.dac_offset = TSENS_DAC_DEFAULT; // DEFAULT: range:-10鈩?~  80鈩? error < 1鈩?
    temp_sensor_set_config(temp_sensor);
    temp_sensor_start();
    ESP_LOGI(TAG, "Temperature sensor started");
    while (1)
    {
        vTaskDelay(10000 / portTICK_RATE_MS);
        temp_sensor_read_celsius(&tsens_out);
        ESP_LOGI(TAG, "Temperature out celsius %f C", tsens_out);
    }
    vTaskDelete(NULL);
}


void bsp_temperature_init(void)
{
    xTaskCreate(tempsensor_example, "temp", 2048, NULL, 5, NULL);
}

